﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>作业缴交</title>
    <script type="text/javascript">
    var mainform;
    var viewType = "${viewType}";
	var dialog=null;
	var terDialog=null;
	
    $(function (){
    	var fileNum=5;
    	$('#homeworkFileUpload').uploadify({
    		formData : {
    			"jsessionid": "<%=request.getSession().getId()%>"
			}, 
   	        swf      : '${ctx}/static/uploadify/uploadify.swf',
   	        uploader : '${ctx}/qso/homeworkSubmit/upload',
   	        width: 100,
   			height:22,
   			multi: true,
   			auto: false,
   			fileObjName: 'hwkAttachment',
   			fileTypeExts: '*.*',
   			fileSizeLimit: 314572800,
   			checkExisting: true,
   			method: 'post',  
   			removeCompleted : false,
   			buttonText:'浏览',
   			queueSizeLimit: fileNum,
   			displayData: 'percentage',
   			queueID:'homework_queue',
   			cancelImg: '${ctx}/static/uploadify/uploadify-cancel.png', 
   			onUploadSuccess : function(file, data, response){
   			},
   			onQueueComplete: function() {
   			},
   			onUploadError : function(file, errorCode, errorMsg){
   				 if(errorCode == -200){
   					 $("#homework_info").append("文件" + file.name + "大小超过最大限制300M！<br/>");
   				 }else{
   					$.ligerDialog.warn("file is:"+file+",errorCode is:"+errorCode+",errorMsg is:"+errorMsg);
   				 }
   			}
   	    });
    	$('#homeworkStart').bind('click', function() {
    		$('#homeworkFileUpload').uploadify('upload','*');
    	});
    	
    	mainform=$("#mainform");
        mainform.ligerForm();
        
        //如果是修改视图,主键不可编辑
        if(viewType=="modify"){
        	 $("#id").attr("readonly", "readonly").removeAttr("validate");
        }
        
        //如果是详细试图,所有字段不可编辑
        if(viewType=="detail"){
        	$("input,select,textarea",mainform).attr("readonly", "readonly");
        }else{
            $.metadata.setType("attr", "validate");
            LG.validate(mainform);
        }

        //渲染按钮
        LG.setFormDefaultBtn(cancel,viewType=="detail" ? null : save);
        
        //调整form-bar
        $(".form-bar").css("width","800px");        
    });
   
    function save(){
        LG.submitForm(mainform, function (result) {
        	if(typeof(result)=="string"){
        		result=eval("("+result+")");
        	}
            if (!result.success) {
                LG.showError('错误:' + result.message);
            }
            else { 
                LG.showSuccess('保存成功', function () { 
                   LG.callParent("courseRegisterList");
                });
            }
        });
    }
    function cancel(){
        var win = window.parent || window;
        if(win.dialog){
        	win.dialog.close();
        }
    }
    function selectQuestion(){
    	dialog=$.ligerDialog.open({title: '选择作业',showMax: true, showToggle: true, showMin: true, isResize: true, modal: true,name:'winselector',width:650, height: 300, url: '${ctx}/qso/homeworkSubmit/toSelect'});
    }
    /*
    *回填文本框里的课程编号、课程名称
    */
    function callBackOK(row){
    	$("#courseId").val(row.courseId);
    	$("#teacherId").val(row.terId);
    	$("#homeworkHId").val(row.id);
    	$("#hwkhTitle").val(row.title);
    	
    	dialog.close();
    }
    /*
     *关闭弹出的课程选择页面
     */
    function callBackCancel(){
        dialog.close();
    }

    function deleteHWKAttachment(id){
		$.ajax({
			type: "POST",
		   	url: '${ctx}/qso/homeworkSubmit/deleteHWKAttachment?id='+id,
		   	success: function(result){
				if(result=='true'){
					var deFile="#deFile_"+id;
					var upFile="#upFile_"+id;
					$(deFile).remove();
					$(upFile).css("display","block");
				}
		   	}
		});
	}
 </script>
</head>

<body>
    <form name="mainform" method="post"  id="mainform" action="${ctx }/qso/homeworkSubmit/save">
        <input type="hidden" name="viewType" value="${viewType}"/>
        <input type="hidden" id="id" name="id" value="${command.id}"/>
        <input type="hidden" id="courseId" name="courseId" value="${command.course.id}"/>
        <input type="hidden" id="studentId" name="studentId" value="${command.student.stuId}"/>
        <input type="hidden" id="teacherId" name="teacherId" value="${command.teacher.terId}"/>
        <input type="hidden" id="homeworkHId" name="homeworkHId" value="${command.homeworkH.id}"/>
        <input type="hidden" id="hwkStatus" name="hwkStatus" value="<c:choose><c:when test="${viewType=='add'}">ED</c:when><c:otherwise>${command.hwkStatus}</c:otherwise></c:choose>" />
        <table cellpadding="0" cellspacing="0" class="l-table-edit" style="width: 95%; margin-top:10px; margin-left:15px;">     
            <tr>
                <td align="right" class="l-table-edit-td" style="width:100px;">作业编号:</td>
                <td align="left" class="l-table-edit-td" style="width:100px;">
						${command.id}
                </td>
                <td align="right" class="l-table-edit-td" style="width:100px;">作业名称:</td>
                <td align="left" class="l-table-edit-td"  style="width:100px;">
                	<input  type="text" id="homeworkName" name="homeworkName" value="${command.homeworkName}" validate="{required:true}" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if>/>
                </td>
           </tr>
           <tr>
                <td align="right" class="l-table-edit-td" style="width:100px;">作业题目:</td>
                <td align="left" class="l-table-edit-td" style="width:100px;">
                	<input  type="text"  readonly="readonly"  id="hwkhTitle" name="hwkhTitle" value="${command.homeworkH.title}"  validate="{required:true}"/>
                </td>
                <td align="right" class="l-table-edit-td" style="width:100px;"></td>
                <td align="left" class="l-table-edit-td" style="width:100px;">
                 	<c:if test="${viewType!='detail'}">
                		<a onclick="selectQuestion()" href="#">选择作业题目</a>
                	</c:if>
                </td>
            </tr>

			<tr>
				<td align="right" class="l-table-edit-td" valign="top"style="width:100px;">选择附件:</td>
				<td align="left" class="l-table-edit-td" style="width:100px;">
				<table class="l-table-edit-td" >
				<c:choose>
					<c:when test="${not empty command.hwkAttachmentList}">
						<c:forEach  items="${command.hwkAttachmentList}" var="hwkFile"  varStatus="status">
							<c:choose>
							<c:when test="${not empty hwkFile.filePath}">
								<tr>
								<td align="left" class="l-table-edit-td" >
								<c:choose>
									<c:when test="${'detail' eq viewType}">
									<div id="deFile_${hwkFile.id}" class="l-table-edit-td">
									${hwkFile.filePath} <a href="${ctx}/qso/homeworkSubmit/download?hwkAttachmentId=${hwkFile.id}">下载</a>	
									</div>
									</c:when>
									<c:otherwise>
									<div id="deFile_${hwkFile.id}" class="l-table-edit-td">
									${hwkFile.filePath} <a onclick="deleteHWKAttachment('${hwkFile.id}');">删除</a>
									</div>
									</c:otherwise>
								</c:choose>
								</td>
								</tr>
							</c:when>
							<c:otherwise>
							<tr>
							<td align="left" class="l-table-edit-td" >
							<div id="upFile_${hwkFile.id}" <c:if test="${not empty hwkFile.filePath}">style="display:none" </c:if> />
							</td>
							</tr>
							</c:otherwise>
							</c:choose>
						</c:forEach>
					</c:when>
					<c:otherwise>
					<tr>
					<td align="left" class="l-table-edit-td" >
           			<input type="file" id="homeworkFileUpload" name="homeworkFileUpload" > </input>
           			<div id="homework_queue" style="max-width:150px;width:150px;"></div>
           			<div id="homework_info"></div>
           			<div id="btnCon">
  						<input type="button" id="homeworkStart" name="homeworkStart" value="开始上传" style="margin-left:auto;margin-right: auto;"/>
  					</div>
  					</td>
  					</tr>
  					</c:otherwise>
  					</c:choose>
  					</table>
				</td>
			
            	<td align="right"  class="l-table-edit-td" style="width:100px;">内容:</td>
                <td align="left" class="l-table-edit-td" style="width:100px;">
                	<textarea cols="200" rows="3" class="l-textarea" id="description" name="description" style="width:400px" <c:if test="${viewType=='detail'}">disabled="disabled"</c:if> >${command.description}</textarea>
                </td>
            </tr>
            
            <c:if test="${viewType=='detail'}">
            	<tr>
            		<td align="right" class="l-table-edit-td" >作业评分:</td>
                	<td align="left" class="l-table-edit-td" >
                		<input disabled="disabled" type="text" id="hwkGrade" name="hwkGrade" value="${command.hwkGrade}" />
               	 	</td>
	                <td align="right" class="l-table-edit-td">作业评语:</td>
	                <td align="left" class="l-table-edit-td"  >
	                	<textarea disabled="disabled" cols="200" rows="3"  class="l-textarea" id="hwkComment" name="hwkComment" style="width:400px" >${command.hwkComment}</textarea>
	                </td>
	            </tr>
            </c:if>
            
        </table> 
    </form>
</body>
</html>